package easy;

import java.math.BigDecimal;
import java.text.DecimalFormat;

public class PlusOne {
    public int[] plusOne(int[] digits) {
        String digit = "";
        for(int i=0;i<digits.length;i++){
            digit+=digits[i]+"";
        }
        BigDecimal bd = new BigDecimal(digit);
        bd = bd.add(BigDecimal.valueOf(1));
        String total = bd.toString();
        int [] plus = new int[total.length()];
        for(int i=0;i<total.length();i++){
            plus[i] = Integer.parseInt(total.charAt(i)+"");
        }
        return plus;
    }

    public int[] plusOne1(int[] digits) {
        int n = digits.length;
        for(int i=n-1; i>=0; i--) {
            if(digits[i] < 9) {
                digits[i]++;
                return digits;
            }

            digits[i] = 0;
        }

        int[] newNumber = new int [n+1];
        newNumber[0] = 1;

        return newNumber;
    }
}
